package me.shingohu.man.intergation;

import android.app.Application;

import com.apkfuns.logutils.LogLevel;
import com.apkfuns.logutils.LogUtils;
import com.blankj.utilcode.util.Utils;

import me.shingohu.man.intergation.activitymanager.TheActivityManager;
import me.shingohu.man.util.CrashHandler;
import me.shingohu.man.util.ToastUtil;

/**
 * Created by hujie on 17/4/15.
 *
 *
 *
 * 启动时需要初始化的工具管理
 */

public class InitUtilManager {


    public static void init(Application application) {
        initCrashHanlder(application);
        initActivityManager(application);
        initBugTags(application);
        initLeakcanary(application);
        initLogUtil();
        initUtils(application);
        initToast(application);
    }

    private static void initUtils(Application application) {
        Utils.init(application);
    }

    private static void initToast(Application application) {

        ToastUtil.initToast(application);
    }


    private static void initLogUtil() {

        LogUtils.getLogConfig()
                .configAllowLog(true)
                .configTagPrefix("shingohu")
                .configShowBorders(true)
                .configFormatTag("%d{HH:mm:ss:SSS} %t %c{-5}")
                .configLevel(LogLevel.TYPE_VERBOSE);
    }


    /**
     * 崩溃监听
     */
    private static void initCrashHanlder(Application application) {
        CrashHandler.getInstance().init(application, (debug, e) -> {
            LogUtils.e(e.toString());
            if (!debug) {
                TheActivityManager.getInstance().finishAll();
            }
        });
    }


    private static void initActivityManager(Application application) {
        TheActivityManager.getInstance().configure(application);
    }

    private static void initBugTags(Application application) {
        BugtagsManager.start(application);
    }

    private static void initLeakcanary(Application application) {
        LeakcanaryManager.initLeakcanary(application);
    }
}
